#ifndef KMALLOC_H_
#define KMALLOC_H_

/*
Copyright (C) 2011 Salil Bhagurkar

This file is part of illusion

illusion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

illusion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with illusion.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <kernel/types.h>

void *kmalloc(uint_t size, char *name);
void kfree(void *addr, uint_t size, char *name);

uint_t kmalloc_pool_memory();
uint_t kmalloc_pool_free_memory();
uint_t memory_available();
uint_t memory_total();


/*
 * Structure that logs all memory allocations from a specified point
 * by their name.
 */
#define KMALLOC_TRACE_NAME_LEN 8
struct kmalloc_trace_entry {
	char name[KMALLOC_TRACE_NAME_LEN];
	void *mem;
	uint_t size;
};
struct kmalloc_trace {
	uint_t count;
	uint_t capacity;
	struct kmalloc_trace_entry entries[];
};
extern struct kmalloc_trace *current_kmalloc_trace;
void kmalloc_debug_traces();
void kmalloc_create_trace(uint_t count);
void kmalloc_free_trace();

#endif /* KMALLOC_H_ */
